home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ad12.zip / ANLGOUT.AD < prev    next >
Text File  |  1990-03-07  |  3KB  |  92 lines

  1.  ┌ * Analog output to flight simulator
  2.  │ 
  3.  │ * Outputs to analog channels are placed on output queue as
  4.  │ * they occur.  Periodically, pending outputs are removed from
  5.  │ * the queue by analogOut and sent to the appropriate channel.
  6.  │ * Calls to enqueue and output are asynconronous.
  7.  │ 
  8.  │ * Operations supported
  9.  │ * analogOut        data to analog channels
  10.  │ * aOut             output value v to analog channel c 
  11.  │ * enQueAnalogOut   put output on queue
  12.  │ * deQueAnalogOut   get output from queue
  13.  │ * initQueAnalogOut initialize output que
  14.  │ 
  15.  │ ┌ * Data structures and other declarations
  16.  │ │ 
  17.  │ │ #include "defines.h"
  18.  │ │ #include "declars.h"
  19.  │ │ 
  20.  │ │ * MaxQue MUST BE AN EXACT POWER OF 2 
  21.  │ │ #define MaxQue      512
  22.  │ │ #define Wrap      MaxQue - 1
  23.  │ │ 
  24.  │ │ /* queue of output control structure pointers */
  25.  │ │ static struct analogOutCtrl *aOutQueue[MaxQue];
  26.  │ │                                                  
  27.  │ │ static int nextTail = 0;      /* next queue input location */
  28.  │ │ static int nextHead = 0;      /* next queue output location */
  29.  │ │ 
  30.  │ │ extern int outputPending;
  31.  │ │ extern int timeOut;
  32.  │ │ extern struct analogOutCtrl anlgOutTable[NumAnalogOut];
  33.  │ └  
  34.  │ 
  35.  │ ┌ * Functions
  36.  │ │ 
  37.  │ │ * Loop over pending transactions and output them
  38.  │ │ ┌ int analogOut() {
  39.  │ │ │ struct analogOutCtrl *oc;
  40.  │ │ │ 
  41.  │ │ │ ╔ For (i = 0; i< 1; i++)
  42.  │ │ │ ║ initAnalog(i);
  43.  │ │ │ ╚ 
  44.  │ │ │ 
  45.  │ │ │ * loop over all data in the aOutQueue structure
  46.  │ │ │ ╔ While ((oc = deQueAnalogOut()) !- (struct outCtrl *) Empty)
  47.  │ │ │ ║ dtoa(oc->channel, oc->word, oc->board);
  48.  │ │ │ ╚ 
  49.  │ │ │ 
  50.  │ │ │ return (timeOut ? Pending : !Pending);
  51.  │ │ └ } 
  52.  │ │ 
  53.  │ │ * Output value v to analog channel c
  54.  │ │ ┌ aOut(int c, int v) {
  55.  │ │ │ anlgOutTable[c].word = v;
  56.  │ │ │ enQueAnalogOut(&anlgOutTable[c]);
  57.  │ │ └  }
  58.  │ │ 
  59.  │ │ * Put output on queue
  60.  │ │ ┌ int enQueAnalogOut(struct analogOutCtrl *obj) {
  61.  │ │ │ * return if queue full
  62.  │ │ │ ╒ If (((nextTail + 1) & Wrap) == nextHead)
  63.  │ │ │ │ return (Full);
  64.  │ │ │ └ 
  65.  │ │ │ * not full, add item to queue
  66.  │ │ │ aOutQueue[nextTail++] = obj;
  67.  │ │ │ nextTail &= Wrap;
  68.  │ │ │ return (NotFull);
  69.  │ │ └ } 
  70.  │ │ 
  71.  │ │ * Get output from queue
  72.  │ │ ┌ struct analogOutCtrl * deQueAnalogOut() {
  73.  │ │ │ 
  74.  │ │ │ ╒ if (nextTail == nextHead)
  75.  │ │ │ │ * return if queue empty 
  76.  │ │ │ │ return ((struct analogOutCtrl *) Empty);
  77.  │ │ │ └ 
  78.  │ │ │ obj = aOutQueue[nextHead++];   * fnx to execute
  79.  │ │ │ nextHead &= Wrap;
  80.  │ │ │ return (obj);
  81.  │ │ └  }
  82.  │ │ 
  83.  │ │ * initialize output queue
  84.  │ │ ┌ void initQueAnalogOut() {
  85.  │ │ │ nextTail = 0;
  86.  │ │ │ nextHead = 0;
  87.  │ │ └ }
  88.  │ │ 
  89.  │ └  
  90.  │ 
  91.  └ 
  92.